package com.ewili.framework.utils;

import java.io.InputStream;
import java.util.Properties;

/**
 * Created by Administrator on 2017/11/18.
 */
public class ConfigUtils {

    private static Properties prop = new Properties();

    static {
        try {
            InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream("config.properties");
            prop.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    public static String getConfig(String key) {
        String k = prop.getProperty(key);
        return k;
    }

    /**
     * 获取配置，可以用泛型控制返回类型
     * 有Map做缓存
     *
     * @param key
     * @param clazz
     * @return
     */
    public static <V> V getConfig(String key, Class<V> clazz) {
        String cfg = getConfig(key);
        return BeanUtils.convert(cfg, clazz);
    }


}
